﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Tron.Players;

namespace Tron
{
    public static class Constants
    {
        // A player must choose one move directions every update.
        public static readonly List<Vector2> PossibleMoveDirections = new List<Vector2>() { Vector2.UnitX, Vector2.UnitY, -Vector2.UnitX, -Vector2.UnitY };

        // The int used to represent an empty block
        public static readonly int EMPTY_BLOCK = -2;




        // The time, in seconds, that a move takes.
        public static readonly double StepDuration = 0.1;

        // The number of rows and columns that the board has.
        // If the board doesn't fit in the window, an exception will be thrown.
        static int rows = 32;
        static int columns = 32;
        public static int Rows
        {
            get
            {
                return rows;
            }
        }
        public static int Columns
        {
            get
            {
                return columns;
            }
        }

        // Whether the game should automatically exit when it is over.
        // This option only applies when the Repeat game type is selected.
        static bool autoExit = true;
        public static bool AutoExit
        {
            get
            {
                return autoExit;
            }
        }

        // Whether the application should get the new player positions and board size from 
        // the RepeatGameTypeSettingsHelper class every game.
        // This option only applies when the Repeat game type is selected.
        static bool useRepeatGameTypeSettingsHelper = true;
        public static bool UseRepeatGameTypeSettingsHelper
        {
            get
            {
                return useRepeatGameTypeSettingsHelper;
            }
        }

        // The width and height of the game window in pixels.
        public static readonly int WindowWidth = 1024;
        public static readonly int WindowHeight = 768;

        // Full screen can show a larger board, but debugging in full screen is difficult
        // without a two-monitor setup.
        public static readonly bool IsFullScreen = false;

        // The name of the custom wall pattern to use.  Wall patterns must be in the Content/Textures/WallPatterns/ folder.
        // If this value is null, no custom wall pattern will be used.
        //public static readonly String WallPattern = "EnhancedReflexAgentTest";
        public static readonly String WallPattern = null;

        // If TurnBased is selected but there is no human player, an exception will be thrown.
        public static readonly GameTypesEnum GameType = GameTypesEnum.Standard;

        // This value controls have many games are played if the Repeat game type is selected.
        public static readonly int RepeatTimes = 100;

        // All these player option lists must be the same length.  An exception will be thrown if they are not.
        #region Player Options

        // The colors of the players.
        public static readonly List<Color> PlayerColors = new List<Color>()
            {
                Color.Red,
                Color.Blue
            };

        // The player types of the players.
        static List<PlayerTypesEnum> playerTypes = new List<PlayerTypesEnum>()
            {
                PlayerTypesEnum.Strategic,
                PlayerTypesEnum.IDSMiniMaxSearch
            };
        public static List<PlayerTypesEnum> PlayerTypes
        {
            get
            {
                return playerTypes;
            }
        }

        // The starting positions of the players.  These must be legal values (integers and within the bounds of the board).
        // The first and last row and first and last column are reserved for the border walls.  Do not start players there.
        static List<Vector2> playerStartingpositions = new List<Vector2>()
            {
                new Vector2(1,1),
                new Vector2(30,30)
            };
        public static List<Vector2> PlayerStartingPositions
        {
            get
            {
                return playerStartingpositions;
            }
        }

        // The starting directions of the players.  These must be legal values ( one of:(1,0),(-1,0),(0,1),(0,-1) )
        public static readonly List<Vector2> PlayerStartingDirections = new List<Vector2>()
            {
                new Vector2(1,0),
                new Vector2(-1, 0)
            };

        // The names of the players (to be displayed).
        public static readonly List<String> PlayerNames = new List<String>()
            {
                "Red",
                "Blue"
            };
        #endregion

        static String scoreOutputPrefix = String.Empty;
        public static String ScoreOutputPrefix
        {
            get
            {
                return scoreOutputPrefix;
            }
        }

        public static void SetOptions(String scoreOutputPrefix, int rows, int columns, List<Vector2> playerStartingpositions)
        {
            Constants.scoreOutputPrefix = scoreOutputPrefix;
            Constants.rows = rows;
            Constants.columns = columns;
            Constants.playerStartingpositions = playerStartingpositions;
        }

        public static string GetStartingPositionsString()
        {
            string s = "";
            foreach (Vector2 v in playerStartingpositions)
            {
                s += "["+((int)v.X).ToString() + "," + ((int)v.Y).ToString() + "] ";
            }
            return s;
        }

        public static string GetOptionsString()
        {
            return "Rows: " + rows + "\n" +
                "Columns: " + columns + "\n" +
                "Starting Positions: " + GetStartingPositionsString() + "\n";
        }

        public static string GetOptionsStringForFile()
        {
            return "r=" + rows + ";c=" + columns + ";sp=" + GetStartingPositionsString();
        }
    }
}
